package cuiyt.juc.unsafe.collection;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author cyt
 * @create 2020-08-31 19:48
 */
public class ListTest {

    private volatile static int num = 10;
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        LinkedList<Integer> linkedList = new LinkedList<>();
        List<Integer> vector = new Vector<>();
        CopyOnWriteArrayList<Object> copyOnWriteArrayList = new CopyOnWriteArrayList<>();

        testLinkList(linkedList);
        // test(list);
    }

    private static void testLinkList(LinkedList<Integer> linkedList) {
        linkedList.push(2);
        /**
         * 返回头元素 、尾部元素，  添加 头、尾部元素
         */
        System.out.println(linkedList.getFirst());
        System.out.println(linkedList.getLast());
        linkedList.addFirst(2);
        linkedList.addLast(3);

        linkedList.removeLast();


        /**
         * 返回头元素 、尾部元素， 但是不删除
         */
        Integer peek = linkedList.peek();
        System.out.println(peek);
        Integer integer = linkedList.peekFirst();
        System.out.println(integer);
        Integer peekLast = linkedList.peekLast();
        System.out.println(peekLast);
        /**
         * 返回头元素 、尾部元素，  并且删除元素
         */
        Integer poll = linkedList.poll();
        System.out.println(poll);
        Integer pollFirst = linkedList.pollFirst();
        System.out.println(pollFirst);
        Integer pollLast = linkedList.pollLast();
        System.out.println(pollLast);
    }


    private static void test(List<Integer> list) {
        for (int i = 0; i <= 10; i++) {
            list.add(i);
        }
        for (int i = 0; i <= 10; i++) {
            list.add(i);
        }
        list.remove(5);
        System.out.println(list.indexOf(3));
        System.out.println(list.lastIndexOf(4));
        Object[] array = list.toArray();
        list.set(1, 2);
        System.out.println(list.remove(2));
        System.out.println(list.get(0));
        System.out.println(list.size());
        System.out.println(list.contains(1));
        for (Integer integer : list) {
            System.out.print(integer + " ");
        }
    }
}
